﻿using System;
using System.Linq.Expressions;

namespace Emico.Linq.Criterion
{
    static class ExpressionHelper
    {
        public static MemberExpression CrateNestExpressionProperty<T>(string propertyName, ParameterExpression parameter)
        {
            Type t = typeof(T);
            MemberExpression pe = null;

            foreach (string property in propertyName.Split('.'))
            {
                if (pe == null)
                {
                    pe = Expression.Property(parameter, t.GetProperty(property));
                }
                else
                {
                    pe = Expression.Property(pe, property);
                }
            }

            return pe;
        }
    }
}
